package com.xyc.manager.merchantxy.controller;


import com.xyc.manager.global.Message;
import com.xyc.manager.merchantxy.bean.WxbCustomer;
import com.xyc.manager.merchantxy.service.MerchantService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("merchant")
public class MerchantController {
        @Resource
        private MerchantService merchantService;
         @RequestMapping("list")
         public String queryMerchantList(Model model) throws Exception {
             List<WxbCustomer> customerList = merchantService.queryMerchantList();
             model.addAttribute("list",customerList);

        return "merchant-list";
    }

    /**
     * springmvc默认取值是@Requestparam.对应页面的数据格式：application/x-www-form-urlencoded(form表单默认格式)
     *
     * @return
     * @throws Exception
     */
    @RequestMapping("save")
    @ResponseBody
    public Message saveMerchant(WxbCustomer customer) throws Exception {

        merchantService.addMerchant(customer);
        Message message = new Message();
        message.setCode(0);
        return message;
    }

}
